using UnityEngine;
using System.Collections;

public class menu : MonoBehaviour {
	
	public string IP = "127.0.0.1";
	public int Port = 25001;
	
	public string username = "";
	
	public GameObject target;
	bool RegisterUI;
	bool LoginUI;
	
	void OnGUI(){
		if(Network.peerType == NetworkPeerType.Disconnected){
			if(GUI.Button(new Rect(100,100,100,25),"Start Cliente")){
				Network.Connect(IP,Port);
			}
			if(GUI.Button(new Rect(100,125,100,25),"Start Server")){
				Network.InitializeServer(10,Port);
			}
		}else{
			if(Network.peerType == NetworkPeerType.Client){
				
				if (RegisterUI == true && LoginUI == false) {
					username = GUI.TextArea( new Rect(100,125,110,25), username);
					if(GUI.Button(new Rect(100,150,110,25), "Registrer")){
						networkView.RPC("Register", RPCMode.Server, username);
						RegisterUI = false;
					}
				} else if (RegisterUI == false && LoginUI == true){
					username = GUI.TextArea( new Rect(100,125,110,25), username);
						if(GUI.Button(new Rect(100,150,110,25), "Login")){
							networkView.RPC("Login", RPCMode.Server, username);
					}	
				}else{
					GUI.Label(new Rect(100,100,100,25), "Cliente");
					
					if(GUI.Button(new Rect(100,125,110,25), "Login")){
						LoginUI = true;	
					}
					
					if(GUI.Button(new Rect(100,150,110,25), "Registrer")){
						RegisterUI = true;
					}
					
					if(GUI.Button(new Rect(100,175,110,25), "Logout")){
						Network.Disconnect(250);
					}
				}
			}
			if(Network.peerType == NetworkPeerType.Server){
				GUI.Label(new Rect(100,100,100,25), "Server");
				GUI.Label(new Rect(100,125,100,25), "Connections: " + Network.connections.Length);
				
				if(GUI.Button(new Rect(100,150,100,25), "Logout")){
					Network.Disconnect(250);
				}
			}
		}		
			
	}
	[RPC]
	void Login(string username) {
		//if (Network.isse)
	}
	
	[RPC]
	void Register(string username) {
		Debug.Log("");
	}	
	
	[RPC]// Mudar em network
	void AskForColor(){
		if(Network.isServer){
			networkView.RPC("ChangerColor",RPCMode.All);
		}
	}
	
	[RPC]
	void ChangerColor(){
		target.renderer.material.color = Color.green;
	}
	
}
